<?php

declare(strict_types=1);

namespace App\Request;

use App\Constants\LoginTypeCode;
use Hyperf\Context\Context;
use Hyperf\Validation\Request\FormRequest;

class LoginRequest extends BaseCommonRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    protected array $scenes = [
        LoginTypeCode::PHONE_REGISTER_LOGIN => ['account', 'code'],// 1
        LoginTypeCode::WECHAT_REGISTER_LOGIN => ['code'], // 2
        LoginTypeCode::TOKEN_LOGIN => ['account'], // 3
        LoginTypeCode::ONE_CLICK_LOGIN => ['accessToken', 'ydToken'], // 4
        LoginTypeCode::IMEI_LOGIN => ['imei'], // 5
        LoginTypeCode::APPLE_LOGIN => ['code'], // 6
        LoginTypeCode::ALI_ONE_CLICK_LOGIN => [], // 7
        LoginTypeCode::PASSWORD_LOGIN => ['account', 'password'], // 8
        LoginTypeCode::UMENG_ONE_CLICK => [], // 9
        LoginTypeCode::GOOGLE_LOGIN => ['google_token'] // 10
    ];

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            LoginTypeCode::PHONE_REGISTER_LOGIN => [
                'account' => 'required|tel:11',
                'password' => 'required',
                'code' => 'required',
            ],
            LoginTypeCode::WECHAT_REGISTER_LOGIN => [
                'code' => 'required',
            ],
            LoginTypeCode::TOKEN_LOGIN => [
                'account' => 'required|tel:11',
            ],
            LoginTypeCode::ONE_CLICK_LOGIN => [
                'accessToken' => 'required',
                'ydToken' => 'required',
            ],
            LoginTypeCode::IMEI_LOGIN => [
                'imei' => 'required',
            ],
            LoginTypeCode::APPLE_LOGIN => [
                'code' => 'required',
            ],
            LoginTypeCode::ALI_ONE_CLICK_LOGIN => [],
            LoginTypeCode::PASSWORD_LOGIN => [
                'account' => 'required|tel:11',
                'password' => 'required',
            ],
            // 'account' => 'required|tel:11',
            // 'password' => 'required',
            // 'code' => 'required',
            // 'accessToken' => 'required',
            // 'ydToken' => 'required',
            // 'imei' => 'required',
            // 'google_token' => 'required',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        $language = Context::get('language');
        if ($language == 'zh-zn') {
            return [
                'account.required' => '账号不能为空',
                'account.tel' => '账号格式不正确',
                'password.required' => '密码不能为空',
                'code.required' => '验证码不能为空',
                'accessToken.required' => 'accessToken不能为空',
                'ydToken.required' => 'ydToken不能为空',
                'imei.required' => 'imei不能为空',
                'google_token.required' => 'google_token不能为空',
            ];
        } elseif ($language == 'zh-hk') {
            return [
                'account.required' => '賬號不能為空',
                'account.tel' => '賬號格式不正確',
                'password.required' => '密碼不能為空',
                'code.required' => '驗證碼不能為空',
                'accessToken.required' => 'accessToken不能為空',
                'ydToken.required' => 'ydToken不能為空',
                'imei.required' => 'imei不能為空',
                'google_token.required' => 'google_token不能為空',
            ];
        } else {
            return [
                'account.required' => 'account is required',
                'account.tel' => 'account is not tel',
                'password.required' => 'password is required',
                'code.required' => 'code is required',
                'accessToken.required' => 'accessToken is required',
                'ydToken.required' => 'ydToken is required',
                'imei.required' => 'imei is required',
                'google_token.required' => 'google_token is required',
            ];
        }
        // return [
        //     'account.required' => 'account is required',
        //     'account.tel' => 'account is not tel',
        //     'password.required' => 'password is required',
        //     'code.required' => 'code is required',
        //     'accessToken.required' => 'accessToken is required',
        //     'ydToken.required' => 'ydToken is required',
        //     'imei.required' => 'imei is required',
        //     'google_token.required' => 'google_token is required',
        // ];
    }


}
